let mongoose = require("mongoose");
mongoose
  .connect(
    "mongodb+srv://3561931711:7s6xVZJuujhqD9yn@cluster0.bzzvo.mongodb.net/"
  )
  .then(() => {
    console.log("数据库连接成功");
  })
  .catch((err) => {
    console.log("数据库连接失败", err);
  });

//用户表
let masterworkerSchema = new mongoose.Schema({
  name: String, //姓名
  img: String, //头像
  expectationaddress: Array, //期望地址
  salarytype: String, //工资类型
  expectedsalary: Number, //期望工资
  tel: String, //电话
  worklist: Array, //工种列表
  personalsituation: String, //个人情况
  distance: {
    type: Number,
    default: Math.round(Math.random() * 100),
  }, //距离km
});

let masterworkerModel = mongoose.model(
  "masterworker",
  masterworkerSchema,
  "masterworker"
);

let relationSchema = new mongoose.Schema({
  img: String,
  name: String,
  address: String,
  work: String,
  time: Date,
});

let alipaySchema = new mongoose.Schema({
  tradeNo: String, //支付宝交易号
  outTradeNo: String, //商户订单号
  amount: Number, // 金额
  createdAt: { type: Date, default: Date.now }, // 创建时间
});

let realnameSchema = new mongoose.Schema({
  name: String,
  idcard: String,
  uid: String,
});

let relationModel = mongoose.model("relation", relationSchema, "relation");
let alipayModel = mongoose.model("alipay", alipaySchema, "alipay");
let realnameModel = mongoose.model("realname", realnameSchema, "realname");

let userSchema = new mongoose.Schema({
  username: String,
  password: String,
});

let userModel = mongoose.model("user", userSchema, "user");

//师傅表
let addressSchema = new mongoose.Schema({
  index: String,
  address: Array,
});

let releaseschema = new mongoose.Schema({
  name: String, //用户姓名
  city: String, //所在城市
  address: String, //工作地址
  tel: String, //联系电话
  salary: Number, //工资
  job: Array, //擅长工种
  text: String, //简介，
  imgs: Array, //图片
  img: String, //头像
  datetime: String,
  isFlag: String,
});
let payListSchema = new mongoose.Schema({
  price: Number,
  name: String,
  time: String,
});
let haosai = new mongoose.Schema({
  name: String,
  img: String,
  address: String,
  phone: String,
  ys: String,
});

let FeedbackMessageSchema = new mongoose.Schema({
  text: String,
  img: Array,
});
let feedbackMessageModel = mongoose.model(
  "feedbackMessage",
  FeedbackMessageSchema,
  "feedbackMessage"
);

let payListModel = mongoose.model("payList", payListSchema, "payList");
let haosaiModel = mongoose.model("haosai", haosai, "haosai");

let addressModel = mongoose.model("address", addressSchema, "address");

let releasemodel = mongoose.model("release", releaseschema, "release");

module.exports = {
  masterworkerModel,
  relationModel,
  alipayModel,
  realnameModel,
  userModel,
  releasemodel,
  payListModel,
  haosaiModel,
  addressModel,
  releasemodel,
  feedbackMessageModel,
};
